<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
    <title></title>
    <div>
        <h3>地理信息</h3>
        <p>地址(addresses): <span id="addresses"></span></p>
        <p>国家(country): <span id="country"></span></p>
        <p>省份(province): <span id="province"></span></p>
        <p>城市(city): <span id="city"></span></p>
        <p>区县(city): <span id="district"></span></p>
        <p>街道(street): <span id="street"></span></p>
        <p>街道门牌号(streetNum): <span id="streetNum"></span></p>
        <p>POI名字(poiName): <span id="poiName"></span></p>
        <p>城市邮编(postalCode): <span id="postalCode"></span></p>
        <p>城市代码(cityCode): <span id="cityCode"></span></p>
    </div>
    <div>
        <h3>动态移动相关信息</h3>
        <p>纬度(latitude): <span id="latitude"></span></p>
        <p>经度(longitude): <span id="longitude"></span></p>
        <p>海拔(altitude): <span id="altitude"></span></p>
        <p>移动方向(heading): <span id="heading"></span></p>
        <p>移动速度(speed): <span id="speed"></span></p>
    </div>

    <div>
        <h3>方法</h3>
        <p onclick="cancel()">清除地理位置监听</p>
    </div>
    <script type="text/javascript">
        var addresses = document.getElementById('addresses');
        var country = document.getElementById('country');
        var province = document.getElementById('province');
        var city = document.getElementById('city');
        var district = document.getElementById('district');
        var street = document.getElementById('street');
        var streetNum = document.getElementById('streetNum');
        var poiName = document.getElementById('poiName');
        var postalCode = document.getElementById('postalCode');
        var cityCode = document.getElementById('cityCode');
        var heading = document.getElementById('heading');
        var speed = document.getElementById('speed');
        var latitude = document.getElementById('latitude');
        var longitude = document.getElementById('longitude');
        var altitude = document.getElementById('altitude');



        // 方法
        // 扩展API加载完毕后调用onPlusReady回调函数
        document.addEventListener( "plusready", onPlusReady, false );
        // 扩展API加载完毕，现在可以正常调用扩展API
        var wid = null;
        function onPlusReady() {
            // 获取位置
            plus.geolocation.getCurrentPosition( function ( p ) {
                addresses.innerText = p.addresses;
                country.innerText = p.address.country;
                province.innerText = p.address.province;
                city.innerText = p.address.city;
                district.innerText = p.address.district;
                street.innerText = p.address.street;
                streetNum.innerText = p.address.streetNum;
                poiName.innerText = p.address.poiName;
                postalCode.innerText = p.address.postalCode;
                cityCode.innerText = p.address.cityCode;

                heading.innerText = p.coords.heading;
                speed.innerText = p.coords.speed;
                latitude.innerText = p.coords.latitude;
                longitude.innerText = p.coords.longitude;
                altitude.innerText = p.coords.altitude;

                console.log(( "Geolocation\n纬度:" + p.coords.latitude + "\n经度:" + p.coords.longitude + "\n海拔:" + p.coords.altitude ));
            }, function ( e ) {
                alert( "Geolocation error: " + e.message );
            } );

            // 监视位置
            wid = plus.geolocation.watchPosition( function ( p ) {
                console.log( "Geolocation\n纬度:" + p.coords.latitude + "\n经度:" + p.coords.longitude + "\n海拔:" + p.coords.altitude );
            }, function ( e ) {
                alert( "Geolocation error: " + e.message );
            } );
        }

        // 清除位置监听
        function cancel() {
            plus.geolocation.clearWatch( wid );
            wid = null;
            console.log('清除位置监听成功');
        }
    </script>
</head>
<body>

</body>
</html>